package com.thrd.basicframework.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;

/**
 * @author: ${唐杰}
 * @date: 2021/3/25
 */
public class TouchImageView extends AppCompatImageView {
    public TouchImageView(@NonNull Context context) {
        super(context);
    }

    public TouchImageView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public TouchImageView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }



    public  void setTouchData(){

    }

    private int touchX;
    private int touchY;
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                touchX = (int) event.getX();
                touchY = (int) event.getY();
             //   Log.e(TAG,"touchX="+touchX);
                break;

            case MotionEvent.ACTION_UP:
                int x = (int) event.getX();
                int y = (int) event.getY();

                if ((Math.abs(x - touchX) < 30) && (Math.abs(y - touchY) < 30)) {

//                    int itemWidth=getWidth()- jiaoDianX;
//                    int item=itemWidth/mJianJuX+1;
//                    Log.e(TAG,"点的位置="+x+"坐标位置"+(jiaoDianX+(mJianJuX*2)));
//                    if((Math.abs(x- jiaoDianX) < 30)&&(Math.abs(y- jiaoDianY)<30)){
//                        ToastUtil.show(getContext(),"点击第一个");
//                    }else
//                    if((Math.abs(x- (jiaoDianX+(mJianJuX*2))) < 30)&&(Math.abs(y- jiaoDianY)<30)){
//                        ToastUtil.show(getContext(),"点击第二个");
//                    }else
//                    if((Math.abs(x- (jiaoDianX+(mJianJuX*4))) < 30)&&(Math.abs(y- jiaoDianY)<30)){
//                        ToastUtil.show(getContext(),"点击第三个");
//                    }


                }
                break;


            default:
                break;
        }

        return super.onTouchEvent(event);
    }
}
